// pages/policy/detail.js
var app = getApp();
var api = require('../../api.js');
var WxParse = require('../../utils/wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  join_active:function(e){
    var that = this
    app.ajax(api.vip_purchase_card, {
      rd_session: wx.getStorageSync('rd_session'),
      pay_money: that.data.info.money,//
      service_time: that.data.info.service_time,//有效期
      activity_id: that.data.info.id,//次卡活动id
      number: that.data.info.number,//使用次数
    }, (res) => {
      console.log(res);
        wx.requestPayment({
          'timeStamp': res.data.timeStamp,
          'nonceStr': res.data.nonceStr,
          'package': res.data.package,
          'signType': res.data.signType,
          'paySign': res.data.paySign,
          'success': function (res) {
            wx.showModal({
              content: '支付成功 ',
              showCancel: false,
              success: function (res) {
                if (res.confirm) {
                  wx.navigateTo({
                    url: '/pages/num_card/list',
                  })
                } else {
                  wx.navigateBack({
                    delta: 1,
                  })
                }
              }
            })
          },
          'fail': function (res) {
            wx.showModal({
              content: '支付失败 ',
              showCancel: false,
              success: function (res) {
                if (res.confirm) {
                  wx.navigateBack({
                    delta: 1,
                  })
                }
              }
            })
          }
        })
      });
    // })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    this.setData({
      id:id
    });
    app.ajax(api.activity_detail, {
      rd_session: wx.getStorageSync('rd_session'),
      activity_id: id
    }, (res) => {
      console.log(res);
      this.setData({
        info: res.data.lists
      })
      console.log(res.data.lists.content);
      WxParse.wxParse('article', 'html', res.data.lists.content, this, 5);
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})